package com.fare.taluo.fetl.domain.entity;

import java.util.Date;
import java.util.List;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.OneToMany;
import javax.persistence.Table;

import org.hibernate.annotations.GenericGenerator;

import com.dayatang.domain.InstanceFactory;
import com.fare.taluo.fetl.domain.base.BaseFetlEntity;
import com.fare.taluo.fetl.domain.repository.IFreightMontorRepository;

/**
 * 
 * @author 416428406@qq.com
 * @since 2013/08/26
 */
@Entity
@Table(name="freight_monitor")
public class FreightMontiorEntity extends BaseFetlEntity {

	/**
	 * 
	 */
	private static final long serialVersionUID = 234234234231L;

	@Id
	@Column(name="ID", length=32)
	@GeneratedValue(generator="system-uuid")
	@GenericGenerator(name="system-uuid",strategy="uuid")
	private String id;
	
	/**
	 * 航班号
	 */
	@Column(name="flightNo")
	private String flightNo;
	
	/**
	 * 航班日期
	 */
	@Column(name="flightDate")
	private Date flightDate;
	
	/**
	 * 抓取日期
	 */
	@Column(name="grabDate")
	private Date grabDate;
	
    /**
     * 当天抓取时，是第几次抓取
     */
	@Column(name="grabNum")
	private int grabNum;
	
	/**
	 * 该航班的舱位数量
	 */
	@Column(name="cabinNum")
	private int cabinNum;
	
	/**
	 * 当前的舱位数量与上一次抓取的舱位数量比较得出的数
	 *//*
	@Column(name="cabinNumForChange")
	private int cabinNumForChange;
	*/
	/**
	 * 最低价
	 */
	@Column(name="lowerPrice")
	private double lowerPrice;
	
	/**
	 * 最高价
	 */
	@Column(name="heightPrice")
	private double higherPrice    ;
	
	/**
	 * 抓取渠道
	 */
	@Column(name="grabChannel")
	private  String  grabChannel  ;
	
	/**
	 * 抓取渠道hbaseKey
	 */
	@Column(name="grabChannelKey")
	private  String  grabChannelKey  ;
	
	/**
	 * 出发地三字码
	 */
	@Column(name="fromCity")
	private  String fromCity   ;
	
	/**
	 * 目的地三字码
	 */
	@Column(name="toCity")
	private  String toCity   ;
	
	/**
	 * 出发地
	 */
	@Column(name="fromCityName")
	private  String fromCityName   ;
	
	/**
	 * 目的地
	 */
	@Column(name="toCityName")
	private String toCityName;
	
	/**
	 * 该记录对应hbase里的rowkey
	 */
	@Column(name="rowKey")
	private String rowKey;
	
	@Column(name="cabinNumForAdd") 
	private int cabinNumForAdd;
	
	@Column(name="cabinNumForDel") 
    private int cabinNumForDel;
	
	
	
	@OneToMany(cascade=CascadeType.ALL,fetch = FetchType.LAZY)
	@JoinColumn(name="monitorId")
	private List<FreightMonitorCabinsEntity> cabinList ;
	
	private static IFreightMontorRepository getIFreightMontorRepository(){
		return InstanceFactory.getInstance(IFreightMontorRepository.class);
	}
//	private static IFreightMontorRepository freightMontorRepository = InstanceFactory.getInstance(IFreightMontorRepository.class);
	
	public List<FreightMontiorEntity>  findAll(){	
		return getIFreightMontorRepository().findAll();
	}
	/**
	 * 根据航班号flightNumber、航班日期departDate、创建日期opDate、起飞城市三字码fromCode，到达城市三字码toCode,查找记录。
	*/	
	public List<FreightMontiorEntity> findByData(String flightNumber,String departDate,String opDate,String fromCode,String toCode,String airHbaseKey){
		return getIFreightMontorRepository().findByData(flightNumber, departDate, opDate, fromCode, toCode,airHbaseKey);
	}
	//仓位变化表查找
	public List<FreightMontiorEntity> findByDataForm(String flightNumber,String departDate,String opDate,String fromCode,String toCode,String airHbaseKey){
		return getIFreightMontorRepository().findByDataForm(flightNumber, departDate, opDate, fromCode, toCode,airHbaseKey);
	}
	
	public List<FreightMontiorEntity> findByConditions(int type, String fromCity,String toCity,String grabChannelKey,String flightNo,String flightDate){
		return getIFreightMontorRepository().findByConditions(type, fromCity,toCity,grabChannelKey,flightNo,flightDate);
	}
	public List<FreightMontiorEntity> findMaxGrabNum(String maxDate,String flightNos) {
		return getIFreightMontorRepository().findMaxGrabNum( maxDate, flightNos);
	}
	
	public List<FreightMontiorEntity> findForLowPrice(String opDate,String flightDate,String flightNo,int size)throws Exception{
		return getIFreightMontorRepository().findForLowPrice(opDate, flightDate, flightNo,size);
	}
	
	public List<FreightMonitorCabinsEntity> findById(String id){
		return getIFreightMontorRepository().findById(id);
	}
	
	public String getId() {
		return id;
	}

	public void setId(String id) {
		this.id = id;
	}

	public String getFlightNo() {
		return flightNo;
	}

	public void setFlightNo(String flightNo) {
		this.flightNo = flightNo;
	}

	

	public int getGrabNum() {
		return grabNum;
	}

	public void setGrabNum(int grabNum) {
		this.grabNum = grabNum;
	}

	public int getCabinNum() {
		return cabinNum;
	}

	public void setCabinNum(int cabinNum) {
		this.cabinNum = cabinNum;
	}

	/*public int getCabinNumForChange() {
		return cabinNumForChange;
	}

	public void setCabinNumForChange(int cabinNumForChange) {
		this.cabinNumForChange = cabinNumForChange;
	}*/

	public double getLowerPrice() {
		return lowerPrice;
	}

	public void setLowerPrice(double lowerPrice) {
		this.lowerPrice = lowerPrice;
	}

	public double getHigherPrice() {
		return higherPrice;
	}

	public void setHigherPrice(double higherPrice) {
		this.higherPrice = higherPrice;
	}

	public String getGrabChannel() {
		return grabChannel;
	}

	public void setGrabChannel(String grabChannel) {
		this.grabChannel = grabChannel;
	}

	public String getFromCity() {
		return fromCity;
	}

	public void setFromCity(String fromCity) {
		this.fromCity = fromCity;
	}

	public String getToCity() {
		return toCity;
	}

	public void setToCity(String toCity) {
		this.toCity = toCity;
	}

	public String getFromCityName() {
		return fromCityName;
	}

	public void setFromCityName(String fromCityName) {
		this.fromCityName = fromCityName;
	}

	public String getToCityName() {
		return toCityName;
	}

	public void setToCityName(String toCityName) {
		this.toCityName = toCityName;
	}

	public String getRowKey() {
		return rowKey;
	}

	public void setRowKey(String rowKey) {
		this.rowKey = rowKey;
	}

	public String getGrabChannelKey() {
		return grabChannelKey;
	}

	public void setGrabChannelKey(String grabChannelKey) {
		this.grabChannelKey = grabChannelKey;
	}


	public Date getFlightDate() {
		return flightDate;
	}


	public void setFlightDate(Date flightDate) {
		this.flightDate = flightDate;
	}


	public Date getGrabDate() {
		return grabDate;
	}


	public void setGrabDate(Date grabDate) {
		this.grabDate = grabDate;
	}


	public List<FreightMonitorCabinsEntity> getCabinList() {
		return findById(this.id);
		
	//	return cabinList;
	}


	public void setCabinList(List<FreightMonitorCabinsEntity> cabinList) {
		this.cabinList = cabinList;
	}


	public int getCabinNumForAdd() {
		return cabinNumForAdd;
	}


	public void setCabinNumForAdd(int cabinNumForAdd) {
		this.cabinNumForAdd = cabinNumForAdd;
	}


	public int getCabinNumForDel() {
		return cabinNumForDel;
	}


	public void setCabinNumForDel(int cabinNumForDel) {
		this.cabinNumForDel = cabinNumForDel;
	}
	
	
	@Override
	public boolean isNew() {
		return getId() == null ;
	}

	@Override
	public boolean existed() {
		if (isNew()) {
			return false;
		}
		return getBaseEntityRepository().exists(getClass(), getId());
	}

	@Override
	public boolean notExisted() {
		return ! existed();
	}
	
	@Override
	public boolean existed(String propertyName, Object propertyValue) {
		// TODO Auto-generated method stub
		return false;
	}
	
	
}
